package dcedit.util;

// Import Java SDK Classes
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;

/** DynamicOmniImage class */
public class DynamicOmniImage extends JLabel implements MouseListener {
    /** Serializable constant */
   public static final long serialVersionUID = 1289514839123L;

   /** Private image fields */
   private ImageIcon defaultImage;
   private ImageIcon hoverImage;
   private ImageIcon clickImage;

   /** Constructor */
   public DynamicOmniImage(String defaultImg, String hoverImg, String clickImg) {
      this(new File(defaultImg), new File(hoverImg), new File(clickImg));
   } // END constructor

   /** Constructor */
   public DynamicOmniImage(File defaultImg, File hoverImg, File clickImg) {
      try {
	     if(null != defaultImg) {
            defaultImage = new ImageIcon(ImageIO.read(defaultImg));
            this.setIcon(defaultImage);
	     } // END if
	     if(null != hoverImg) {
            hoverImage = new ImageIcon(ImageIO.read(hoverImg));
	     } // END if
	     if(null != clickImg) {
            clickImage = new ImageIcon(ImageIO.read(clickImg));
	     } // END if
	     this.addMouseListener(this);
      } catch(Exception e) {}
   } // END constructor

   /** Constructor */
   public DynamicOmniImage(InputStream defaultImg, InputStream hoverImg, InputStream clickImg) {
      try {
	     if(null != defaultImg) {
            defaultImage = new ImageIcon(ImageIO.read(defaultImg));
            this.setIcon(defaultImage);
	     } // END if
	     if(null != hoverImg) {
            hoverImage = new ImageIcon(ImageIO.read(hoverImg));
	     } // END if
	     if(null != clickImg) {
            clickImage = new ImageIcon(ImageIO.read(clickImg));
	     } // END if
	     this.addMouseListener(this);
      } catch(Exception e) {}
   } // END constructor

   /** Constructor */
   public DynamicOmniImage(ImageInputStream defaultImg, ImageInputStream hoverImg, ImageInputStream clickImg) {
      try {
	     if(null != defaultImg) {
            defaultImage = new ImageIcon(ImageIO.read(defaultImg));
            this.setIcon(defaultImage);
	     } // END if
	     if(null != hoverImg) {
            hoverImage = new ImageIcon(ImageIO.read(hoverImg));
	     } // END if
	     if(null != clickImg) {
            clickImage = new ImageIcon(ImageIO.read(clickImg));
	     } // END if
	     this.addMouseListener(this);
      } catch(Exception e) {}
   } // END constructor

   /** Constructor */
   public DynamicOmniImage(URL defaultImg, URL hoverImg, URL clickImg) {
      try {
	     if(null != defaultImg) {
            defaultImage = new ImageIcon(ImageIO.read(defaultImg));
            this.setIcon(defaultImage);
	     } // END if
	     if(null != hoverImg) {
            hoverImage = new ImageIcon(ImageIO.read(hoverImg));
	     } // END if
	     if(null != clickImg) {
            clickImage = new ImageIcon(ImageIO.read(clickImg));
	     } // END if
	     this.addMouseListener(this);
      } catch(Exception e) {}
   } // END constructor

   /** Mouse Click Listener method */
   public void mouseClicked(MouseEvent me) {}

   /** Mouse Entered Listener method */
   public void mouseEntered(MouseEvent me) {
      if(null != hoverImage) {
         JLabel label = (JLabel)me.getComponent();
         label.setIcon(hoverImage);
      } // END if
   } // END mouseEntered

   /** Mouse Exited Listener method */
   public void mouseExited(MouseEvent me) {
      if(null != defaultImage) {
         JLabel label = (JLabel)me.getComponent();
         label.setIcon(defaultImage);
      } // END if
   } // END mouseExited

   /** Mouse Pressed Listener method */
   public void mousePressed(MouseEvent me) {
      if(null != clickImage) {
         JLabel label = (JLabel)me.getComponent();
         label.setIcon(clickImage);
      } // END if
   } // END mousePressed

   /** Mouse Released Listener method */
   public void mouseReleased(MouseEvent me) {
      if(null != hoverImage) {
         JLabel label = (JLabel)me.getComponent();
         label.setIcon(hoverImage);
      } // END if
   } // END mouseReleased
} // END class DynamicOminImage